package framework

import (
	"crypto/rand"
	"encoding/hex"
	"fmt"
	os2 "github.com/beherochuling/beesoft_api/app/helper/os/file"
	"os"

	"github.com/gogf/gf/v2/os/gfile"
)

var Framework framework

type framework struct {
	rootDir string
}

func (r *framework) RootDir() string {
	if r.rootDir != "" {
		return r.rootDir
	}

	rootDir := gfile.SelfDir()
	if gfile.Name(rootDir) == "bin" {
		rootDir = gfile.Dir(rootDir)
	}

	r.rootDir = os2.File.FormatPath(rootDir)

	return r.rootDir
}
func DeviceId() string {
	hostname, err := os.Hostname()
	if err != nil {
		panic(err)
	}

	randomBytes := make([]byte, 16)
	_, err = rand.Read(randomBytes)
	if err != nil {
		panic(err)
	}

	randomHex := hex.EncodeToString(randomBytes)

	return fmt.Sprintf("%s-%s", hostname, randomHex)
}
